import {
  Entity,
  Column,
  ManyToOne,
  JoinColumn,
  OneToOne,
  PrimaryColumn
} from "typeorm";
import { BblAttach } from "./attach.entity";
import { BblHomeSection } from "./home.section.entity";

@Entity("BBL_HOME_CONTENT")
export class BblHomeContent {
  @PrimaryColumn({
    name: "HOME_CONTENT_ID",
    type: "varchar",
    length: 50,
    comment: "内容ID"
  })
  contentId: string;

  /**
   * 内容类型, 0:图片，1:文本
   */
  @Column({
    name: "HOME_CONTENT_TYPE",
    type: "int",
    nullable: false,
    comment: "内容类型, 0:图片，1:文本"
  })
  contentType: number;

  @OneToOne((type) => BblAttach, { createForeignKeyConstraints: false })
  @JoinColumn({
    name: "ATTACH_ID",
    referencedColumnName: "attId"
  })
  contentImg: BblAttach;

  @Column({
    name: "HOME_CONTENT_TEXT",
    type: "text",
    nullable: true,
    comment: "内容文本"
  })
  contentText: string;

  @Column({
    name: "HOME_CONTENT_INDEX",
    type: "int",
    comment: "内容排序"
  })
  contentIndex: number;

  @ManyToOne((type) => BblHomeSection, (section) => section.sectionContents, {
    createForeignKeyConstraints: false
  })
  @JoinColumn({
    name: "HOME_SECTION_ID",
    referencedColumnName: "sectionId"
  })
  section: BblHomeSection;
}
